<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>发送 GET 请求</title>
  </head>
  <body>
    <button>点击发送 AJAX 请求</button>
    <script>
      //获取 button 按钮
      let btn = document.querySelector("button");

      //绑定事件  GET
      btn.onclick = function () {
        //1. 创建请求 对 象 
        let xhr = new XMLHttpRequest();
        //初始化
        xhr.open("get", "http://127.0.0.1:8080/server/100?_t=" + Date.now()); // params
        //3. 发送
        xhr.send();
        //4. 绑定事件 处理响应结果
        xhr.onreadystatechange = function () {
          //判断
          if (xhr.readyState === 4) {
            console.log(xhr.response);
          }
        };
      };
    </script>
  </body>
</html>
